package com.example.consult.service;

import com.example.consult.mapper.EmployeeMapper;
import com.example.consult.mapper.RecordMapper;
import com.example.consult.util.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class ConsultService {
    @Autowired
    RecordMapper recordMapper;
    @Autowired
    EmployeeMapper employeeMapper;
    @Autowired
    RedisUtil redisUtil;
    public String getFreeEmployee(){
        Map<Object,Object> map = redisUtil.hmget("Employee");
        //遍历map中的值
        for (Object key : map.keySet()) {
            if(map.get(key).equals("")||map.get(key)==null){
                return key.toString();
            }
        }
        return null;
    }

    public String setSatisfy(String employeeAccount,double add){
        int time=recordMapper.getConsultTimeByEmployee(employeeAccount);
        double grade = recordMapper.getConsultTimeByEmployee(employeeAccount);
        //计算平均分
        grade = (grade+add)/time;
        //更新平均分
        employeeMapper.setSatisfy(grade);
        return "ok";
    }
}
